package com.anxin.act.busFlow.service;

import com.anxin.act.busFlow.dao.WfBusRoundDao;
import com.anxin.act.busFlow.dto.AddInvestDTO;
import com.anxin.act.busFlow.entity.WfBusRound;
import com.anxin.common.utils.StringUtils;
import com.anxin.framework.web.entity.AjaxResult;
import com.anxin.framework.web.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 投资流程轮次Service业务层处理
 *
 * @author jbs
 * @date 2022-08-25
 */
@Service
public class WfBusRoundService extends BaseService<WfBusRoundDao, WfBusRound>{
    @Autowired
    private WfBusRoundDao wfBusRoundDao;

    /**
     * 查询投资流程轮次
     *
     * @param id 投资流程轮次ID
     * @return 投资流程轮次
     */
    public WfBusRound getById(String id){
        return wfBusRoundDao.getById(id);
    }

    /**
     * 查询投资流程轮次列表
     *
     * @param wfBusRound 投资流程轮次
     * @return 投资流程轮次
     */
    public List<WfBusRound> findList(WfBusRound wfBusRound){
        return wfBusRoundDao.findList(wfBusRound);
    }

    /**
     * 根据业务Id查询轮次信息
     * @param busId 业务ID
     * @return
     */
    public List<WfBusRound> findByBusId(String busId){
        WfBusRound wfBusRound = new WfBusRound();
        wfBusRound.setBusId(StringUtils.symbolHandler(busId));
        return wfBusRoundDao.findList(wfBusRound);
    }

    /**
     * 保存投资流程轮次
     *
     * @param wfBusRound 投资流程轮次
     * @return 结果
     */
    public int save(WfBusRound wfBusRound){
        return super.save(wfBusRound);
    }

    /**
     * 获取首轮投资信息
     * @param busId 业务ID
     * @return
     */
    public WfBusRound getFirstInvest(String busId){
        WfBusRound wfBusRound = new WfBusRound();
        wfBusRound.setBusId(busId);
        wfBusRound.setNum(1);
        List<WfBusRound> wfBusRoundList = wfBusRoundDao.findList(wfBusRound);
        if (wfBusRoundList.size() > 0){
            return wfBusRoundList.get(0);
        }
        return null;
    }


    /**
     * 获取首轮投资名称
     * @param busId 业务ID
     * @return
     */
    public String getFirstInvestName(String busId){
        WfBusRound wfBusRound = this.getFirstInvest(busId);
        if (wfBusRound != null){
            return wfBusRound.getName();
        }
        return null;
    }

    /**
     * 添加公司轮次
     * @return
     */
    public WfBusRound saveNewRound(AddInvestDTO addInvestDTO,String nodeType){
        WfBusRound wfBusRound = new WfBusRound();
        wfBusRound.setBusId(addInvestDTO.getBusId());
        wfBusRound.setName(addInvestDTO.getNewInvestName());
        wfBusRound.setType(nodeType);
        this.save(wfBusRound);
        return wfBusRound;
    }

    /**
     * 根据业务ID获取轮次数据
     * @param busId 业务ID
     * @return
     */
    public List<WfBusRound> findByRoundId(String busId){
        WfBusRound wfBusRound = new WfBusRound();
        wfBusRound.setBusId(busId);
        return wfBusRoundDao.findList(wfBusRound);
    }

}
